﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SW2A311A
{
    public abstract class ElectricOven : Product, ISmileyRating, IEnergyClass
    {
        #region Instansvariabler
        public Dimensions Dimension
        {
            get { return _dimension; }
            private set { _dimension = value; }
        }
        private Dimensions _dimension;

        public double Volume
        {
            get { return _volume; }
            private set
            {
                if (value > 0)
                    _volume = value;
                else
                    throw new ArgumentOutOfRangeException("Volume", "Skal være positivt tal");
            }
        }
        private double _volume;

        public double EnergyConsumption
        {
            get { return _energyConsumption; }
            private set
            {
                if (value > 0)
                    _energyConsumption = value;
                else
                    throw new ArgumentOutOfRangeException("Energyconsumption", "Skal være positivt tal");
            }
        }
        private double _energyConsumption;

        public EEnergyClass EnergyClass { get; private set; }
        public ESmiley Smiley;
        #endregion

        #region Constructors
        // ElectricOven instantieres med indput parametre til alle fields og proporties, 
        // og sender dem videre til superklassen Product.
        public ElectricOven(string name, double price, Dimensions dimension, double volume, double energyConsumption)
            : base(name, price)
        {
            Dimension = dimension;
            Volume = volume;
            EnergyConsumption = energyConsumption;
            EnergyClass = GetEnergyClass();
        }
        #endregion

        #region Metoder
        public abstract ESmiley GetSmiley();

        // Elovenens energiklasse afhænger af flere parameter: 
        // Ovnens størrelse (volumen i liter) samt dens energiforbrug (kWh).
        // så først checkes hvilken størrelseskategori ovenen tilhøre, 
        // derefter hvor meget strøm den bruger for endeligt at komme frem til hvilken energiklasse ovnen tilhøre
        public virtual EEnergyClass GetEnergyClass()
        {
            if (new Range(65, int.MaxValue).IsBetweenOrEqualMin(Volume))
            {
                if (new Range(0.0, 1.0).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.A;
                else if (new Range(1.0, 1.2).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.B;
                else if (new Range(1.2, 1.4).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.C;
                else if (new Range(1.4, 1.6).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.D;
                else if (new Range(1.6, 1.8).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.E;
                else if (new Range(1.8, 2.0).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.F;
                else
                    return EEnergyClass.G;
            }
            else if (new Range(35, 65).IsBetweenOrEqualMin(Volume))
            {
                if (new Range(0.0, 0.8).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.A;
                else if (new Range(0.8, 1.0).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.B;
                else if (new Range(1.0, 1.2).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.C;
                else if (new Range(1.2, 1.4).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.D;
                else if (new Range(1.4, 1.6).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.E;
                else if (new Range(1.6, 1.8).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.F;
                else
                    return EEnergyClass.G;
            }
            else
            {
                if (new Range(0.0, 0.6).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.A;
                else if (new Range(0.6, 0.8).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.B;
                else if (new Range(0.8, 1.0).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.C;
                else if (new Range(1.0, 1.2).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.D;
                else if (new Range(1.2, 1.4).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.E;
                else if (new Range(1.4, 1.6).IsBetweenOrEqualMin(EnergyConsumption))
                    return EEnergyClass.F;
                else
                    return EEnergyClass.G;
            }
        }

        #region Equals metoder
        public override bool Equals(object obj)
        {
            ElectricOven p = obj as ElectricOven;

            if (this.GetType() != obj.GetType())
                return false;

            return base.Equals(obj) &&
                Dimension.Equals(p.Dimension) &&
                Volume == p.Volume &&
                EnergyConsumption == p.EnergyConsumption &&
                EnergyClass == p.EnergyClass &&
                Smiley == p.Smiley;
        }

        public bool Equals(ElectricOven p)
        {
            return base.Equals((Product)p) &&
                Dimension.Equals(p.Dimension) &&
                Volume == p.Volume &&
                EnergyConsumption == p.EnergyConsumption &&
                EnergyClass == p.EnergyClass &&
                Smiley == p.Smiley;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() ^ Dimension.GetHashCode() ^
                Volume.GetHashCode() ^ EnergyConsumption.GetHashCode() ^
                EnergyClass.GetHashCode() ^ Smiley.GetHashCode();
        }
        #endregion
        #endregion
    }
}